﻿using System;
using System.Linq;
using System.Collections.Generic;

namespace Sonce.Editor.Data
{
    public class Table<T> : List<T> where T : IPrimaryKey
    {
        public new void Add(T item)
        {
            #region Auto increment primary key
            int id = 0;
            if (base.Count > 0)
            {
                var last = this.OrderBy(e => e.Id).Last();
                //var last = this.OrderByDescending(e => e.Id).First();
                id = last.Id + 1;
            }
            else
            {
                id = 1;
            }
            item.Id = id;
            #endregion

            base.Add(item);
        }
    }
}
